package com.qiaoanju.hystrix;

import com.qiaoanju.domain.UserDomain;
import com.qiaoanju.feign.UserFeignClientByFallbackFactory;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class HystrixUserClientFallbackFactory implements FallbackFactory<UserFeignClientByFallbackFactory> {
    @Override
    public UserFeignClientByFallbackFactory create(Throwable throwable) {
        return new UserFeignClientByFallbackFactory() {
            @Override
            public UserDomain findById(Long id) {
                UserDomain user = new UserDomain();
                user.setId(11L);
                user.setUsername("use FallbackFactory");
                user.setPassword("findById");
                return user;
            }

            @Override
            public UserDomain postUser(UserDomain user) {
                user.setId(12L);
                user.setUsername("use FallbackFactory");
                user.setPassword("postUser");
                return user;
            }

            @Override
            public UserDomain login(Map<String, Object> map) {
                UserDomain user = new UserDomain();
                user.setId(13L);
                user.setUsername("use FallbackFactory");
                user.setPassword("postUser");
                return user;
            }
        };
    }
}
